package com.bob.web.controller.system;

import com.bob.web.common.constant.Page;
import com.bob.web.controller.BaseController;
import com.bob.web.entity.system.Resource;
import com.bob.web.entity.system.Role;
import com.bob.web.service.system.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 名称: SystemController<br>
 * 描述:<br>
 * 类型: JAVA<br>
 * 最近修改时间:2017/7/21 15:46<br>
 *
 * @author BoYangsh
 * @version [版本号, V1.0]
 * @since 2017/7/21 15:46
 */
@RestController
@RequestMapping("system")
public class SystemController extends BaseController{

	@Autowired
	private SystemService systemService;

	/**
	 * 查找资源的分页数据
	 * @param page
	 */
	@RequestMapping("find_resource_page")
	public Page<Resource> findResourcePage(Page<Resource> page) {
		systemService.findResourcePage(page);
		return page;
	}

	/**
	 * 添加资源
	 * @param resource
     */
	@RequestMapping("add_resource")
	public void addResource(Resource resource) {
		systemService.addResource(resource);
	}

	/**
	 * 查找一级菜单
	 * @return
	 */
	@RequestMapping("find_first_level_resource")
	public List<Resource> findFirstLevelResource() {
		return systemService.findFirstLevelResource();
	}
	
	/**
	 * 查找二级菜单
	 * @return
	 */
	@RequestMapping("find_second_level_resource")
	public List<Resource> findSecondLevelResource() {
		return systemService.findSecondLevelResource();
	}

	/**
	 * 删除资源
	 * @param id
	 */
	@RequestMapping("remove_resource")
	public void addResource(String id) {
		systemService.removeResource(id);
	}

	/**
	 * 查找角色的分页数据
	 * @param page
	 * @return
     */
	@RequestMapping("find_role_page")
	public Page<Role> findRolePage(Page<Role> page) {
		systemService.findRolePage(page);
		return page;
	}

	/**
	 * 添加角色
	 * @param role
     */
	@RequestMapping("add_role")
	public void addRole(Role role) {
		systemService.addRole(role);
	}

	/**
	 * 获得树形资源
	 * @param roleId 角色号
	 * @return
     */
	@RequestMapping("find_resource_tree")
	public List<Resource> findResourceTree(Long roleId) {
		return systemService.findResourceTree(roleId);
	}

	/**
	 * 为角色分配资源
	 * @param role
	 */
	@RequestMapping("allocate_resource_for_role")
	public void allocateResourceForRole(Role role) {
		systemService.allocateResourceForRole(role);
	}

	/**
	 * 查找所有的角色
	 * @return
     */
	@RequestMapping("find_all_roles")
	public List<Role> findAllRoles() {
		return systemService.findAllRoles();
	}

	/**
	 * 根据管理员id查找角色
	 * @param adminId
	 * @return
     */
	@RequestMapping("find_all_roles_by_admin_id")
	public List<Role> findAllRolesByAdminId(Long adminId) {
		return systemService.findAllRolesByAdminId(adminId);
	}
}
